﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace testDsmlSvr
{
  class testPostReq
  {



    public static void go()
    {


      string postMsg = @"<?xml version='1.0' encoding='UTF-8'?>
<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/' >
  <s:Body>
    <batchRequest
      xmlns:xsd='http://www.w3.org/2001/XMLSchema'
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xmlns='urn:oasis:names:tc:DSML:2:0:core'
      requestID='Batch of search requests'
      responseOrder='Unordered'
    >
      <searchRequest
        dn='cn=config'
        requestID='search on Root DSE'
        scope='wholeSubtree'
        derefAliases='neverDerefAliases'
        typesOnly='false'
      >
        <filter>
          <present name='objectClass'/>
        </filter>
      </searchRequest>
    </batchRequest>
  </s:Body>
</s:Envelope>
";

      //postMsg = @"<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><request xmlns='http://tempuri.org/'><batchRequest requestID='Batch of search requests' responseOrder='Unordered' xmlns=''><searchRequest dn='' requestID='search on Root DSE' scope='baseObject' derefAliases='neverDerefAliases' typesOnly='false'><filter><present name='objectClass'/></filter><attributes><attribute name='namingContexts'/><attribute name='supportedLDAPversion'/><attribute name='vendorName'/><attribute name='vendorVersion'/><attribute name='supportedSASLMechanisms'/></attributes></searchRequest></batchRequest></request></s:Body></s:Envelope>";
      postMsg = postMsg.Replace('\'', '"');

      var wb = new WebClient();
      //wb.Headers.Add("Content-Type", "application/xml; charset=utf-8");
      //wb.Headers.Add("Content-Type", "text/xml");
      
      //wb.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0");
      //wb.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
      //wb.Headers.Add(HttpRequestHeader.ContentEncoding, "utf-8");

      wb.Headers.Add("Content-Type", "text/xml; charset=utf-8");
      wb.Headers.Add("SOAPAction", "\"Process\"");

      //wb.Encoding = System.Text.Encoding.UTF8;


      //wb.Credentials = CredentialCache.DefaultCredentials;
      wb.Credentials = new NetworkCredential("sidaa", "Kacenka.24");

      //string response = wb.UploadString("http://localhost:4519/LdConnection.svc", "POST", postMsg);
      string response = wb.UploadString("https://eagri.cz/ssl/basic-app/uhul/wtest/LDS/LdConnection.svc", "POST", postMsg);
    

      Console.WriteLine(response);


    }

  }




}
